/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is KazeOS Framework.
  
  The Initial Developer of the Original Code is
  ALCARAZ Marc (aka eKameleon) <ekameleon@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2004-2010
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  
*/

package evisio.states.chat.display 
{
    import system.Strings;

    import vegas.display.Background;
    import vegas.ioc.factory.ObjectFactory;

    import flash.events.Event;
    import flash.media.Video;
    import flash.text.TextField;

    /**
     * The guest display class.
     */
    public class Guest extends Background 
    {
        /**
         * Creates a new Guest instance.
         */
        public function Guest()
        {
            super();
        }
        
        /**
         * The IoC factory reference of this screen.
         */
        public var factory:ObjectFactory ;
        
        /**
         * Determinates the label textfield reference.
         */
        public function get field():TextField 
        {
            return _field ;
        }
        
        /**
         * @private
         */
        public function set field( tf:TextField ):void 
        {
            _field = tf ;
            refreshField() ;
        }       
        
        /**
         * Indicates the current label value.
         */
        public function get label():String 
        {
            return _label ;
        }
        
        /**
         * @private
         */
        public function set label( str:String ):void 
        {
            _label = str ;
            refreshField() ;
        }        
        
        /**
         * The String pattern to format the label. 
         */
        public var labelPattern:String ;
        
        /**
         * The video reference of this screen.
         */
        public var video:Video ;
        
        /**
         * Reset the form.
         */
        public function reset( e:Event = null ):void
        {
            if ( field != null )
            {
                field.htmlText = "" ;
            }
        }  
        
        /**
         * Refresh the label field.
         */
        protected function refreshField():void
        {
            if ( _field != null )
            {
               _field.htmlText = Strings.format( labelPattern || "" , _label || "" ) ;
            }
        }
        
        /**
         * Invoked when the display is removed from the stage.
         */
        protected override function removedFromStage( e:Event = null ):void
        {
            if( video != null )
            {
                   video.clear() ;
            }
        }
        
        /**
         * @private
         */
        private var _field:TextField ;
        
        /**
         * @private
         */
        private var _label:String ;
    }
}
